package com.sskj.one.banker;

import com.hjq.toast.ToastUtils;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.one.bean.AgreeBean;
import com.sskj.one.bean.AvailableBean;
import com.sskj.one.bean.BankerInfoBean;
import com.sskj.one.presenter.BasePresenter;

/**
 * @author Hey
 * Create at  2019/05/21
 */
class BankerPresenter extends BasePresenter<BankerFragment> {

    public void getBankerInfo(boolean showLoading, int page, int size) {
        httpService.getBankInfo(page, size)
                .tag(this)
                .execute(new JsonCallBack<HttpData<BankerInfoBean>>(showLoading ? this : null) {
                    @Override
                    public void onHTTPSuccess(HttpData<BankerInfoBean> data) {
                        mView.getBankInfoOK(data.getData());
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.stopRefresh();
                    }
                });
    }

    public void getAgree(String type) {
        httpService.getAgree(type)
                .tag(this)
                .execute(new JsonCallBack<HttpData<AgreeBean>>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData<AgreeBean> data) {
                        mView.getAgreeOK(data.getData());
                    }
                });
    }

    public void transferOut(String pwd) {
        httpService.transferOut(MD5Util.getFiveMd5Value(pwd))
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData data) {
                        ToastUtils.show("转出成功");
                        getBankerInfo(false, 1, 15);
                    }
                });
    }

    public void tranferIn(String money, String pwd) {
        httpService.transferIn(money, MD5Util.getFiveMd5Value(pwd))
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData data) {
                        ToastUtils.show("转入成功");
                        getBankerInfo(false, 1, 15);
                    }
                });
    }

    public void getAvailableFenhong() {
        httpService.getAvailableFenhong()
                .tag(this)
                .execute(new JsonCallBack<HttpData<AvailableBean>>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData<AvailableBean> data) {
                        mView.getAvailableFenhongOK(data.getData());
                    }
                });
    }

    public void lingqu() {
        httpService.lingquFenhong()
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData data) {
                        ToastUtils.show("领取成功");
                    }
                });
    }
}
